<template>
	<view class="content" :style="{background: `url(${imgPath}storage/home/home_bg.png)`}">
		<view class="box">
			<view class="xyInfo">
				<view class="title">
					添油信息
				</view>
				<view class="xyInfo-box">
					<view class="item">
						<view class="label">
							添油金额：
						</view>
						<view class="text">
							{{infoForm.price}}（元）
						</view>
					</view>
					<view class="item">
						<view class="label">
							功德主姓名：
						</view>
						<view class="text">
							{{infoForm.name}}
						</view>
					</view>
					<view class="item">
						<view class="label">
							联系电话：
						</view>
						<view class="text">
							{{infoForm.mobile}}
						</view>
					</view>
					<view class="item">
						<view class="label">
							性别：
						</view>
						<view class="text">
							{{infoForm.sex}}
						</view>
					</view>
					<view class="item">
						<view class="label">
							生辰：
						</view>
						<view class="text">
							{{infoForm.birthdate||''}}
						</view>
					</view>
					<view class="item">
						<view class="label">
							地址：
						</view>
						<view class="text">
							{{infoForm.address}}
						</view>
					</view>
				</view>
			</view>
			<view class="orderInfo">
				<view class="title">
					订单信息
				</view>
				<view class="xyInfo-box">
					<view class="item">
						<view class="label">
							合计金额：
						</view>
						<view class="text" style="color: #D06122;">
							{{infoForm.price}}
						</view>
					</view>
					<view class="item">
						<view class="label">
							订单编号：
						</view>
						<view class="text" style="display: flex;">
							<text style="padding-right: 14rpx;">{{infoForm.order_no}}</text>
							<u-icon name="file-text" color="#EA6F29" @click="replication(infoForm.order_no)"></u-icon>
						</view>
					</view>
					<view class="item">
						<view class="label">
							创建时间：
						</view>
						<view class="text">
							{{infoForm.create_time}}
						</view>
					</view>
				</view>
			</view>
			<view class="button-box">
				<view class="left">
					合计：¥{{infoForm.price}}
				</view>
				<view class="right">
					<view class="left-btn" @click="delOrder(infoForm.order_id)" v-if="infoForm.status == 3">
						删除记录
					</view>
					<view class="left-btn" @click="cancelOrder(infoForm.order_id)" v-if="infoForm.status == 1">
						取消订单
					</view>
					<view class="right-btn" @click="payOrder(infoForm.order_id)" v-if="infoForm.status == 1">
						去支付
					</view>
					<view class="right-btn" @click="buyAgain(infoForm)"
						v-if="infoForm.status == 2 || infoForm.status == 3">
						再次祈愿
					</view>
				</view>
			</view>
		</view>

		<uni-popup ref="popup" type="center">
			<view class="pay-popup">
				<view class="close" @click="close">
					<u-icon name="close" color="#fff" size="28" bold></u-icon>
				</view>
				<view class="successful-img">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/paysuccessful.png'" width="192rpx"
						height="40rpx"></u--image>
				</view>
				<view class="popup-box"
					:style="{background: `url(${imgPath}storage/home/paybg.png)`,backgroundSize: '100%'}">
					<view class="ok-img">
						<u--image :showLoading="true" :src="imgPath + 'storage/home/payok.png'" width="150rpx"
							height="152rpx"></u--image>
					</view>
					<view class="text">
						您已成功支付，可到个人中心查看！
					</view>
					<view class="btns">
						<view class="left-btn" @click="goHome">
							返回首页
						</view>
						<view class="right-btn" @click="showDetail">
							查看订单
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		pay
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				infoForm: {},
				id: ''
			}
		},
		onLoad(e) {
			this.getBlessingorderInfo(e.id)
		},
		methods: {
			replication(text) {
				uni.setClipboardData({
					data: text,
					success: function() {
						console.log('复制成功');
					}
				});
			},
			getBlessingorderInfo(order_id) {
				this.$api.blessingorderinfo({
					order_id
				}).then(res => {
					this.infoForm = res.data
				})
			},
			payOrder(id) {
				pay(id, 2, (() => {
					this.getBlessingorderInfo(id)
					this.open()
				}))
			},
			cancelOrder(order_id) {
				this.$api.blessingordercancel({
					order_id
				}).then(res => {
					this.getBlessingorderInfo(order_id)
				})
			},
			delOrder(order_id) {
				this.$api.blessingorderdel({
					order_id
				}).then(res => {
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2]
					if (prevPage.$vm.updata != undefined) prevPage.$vm.updata()
					uni.navigateBack({
						delta: 1
					})
				})
			},
			buyAgain(obj) {
				this.$api.blessingordercreate({
					order_type: 2,
					type: obj.type,
					price: obj.price,
					name: obj.name,
					mobile: obj.mobile,
					sex: obj.sex,
					birthdate: obj.birthdate,
					address: obj.address,
					temple_id: obj.temple_id,
					remark: obj.remark
				}).then(res => {
					pay(res.data.id, 2, (() => {
						this.id = res.data.id
						this.open()
					}))
				})
			},
			close() {
				this.$refs.popup.close()
			},
			open() {
				this.$refs.popup.open()
			},
			goHome() {
				this.close()
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			showDetail() {
				if (this.id != '') this.getBlessingorderInfo(this.id)
				this.close()
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		min-height: 100vh;
		z-index: -1;
	}

	.box {
		padding: 20rpx 30rpx 0 30rpx;
	}

	.xyInfo {
		height: 434rpx;
		background: #FEF1DC;
		border-radius: 20rpx;
		margin-bottom: 16rpx;
		padding: 0 30rpx;
		box-sizing: border-box;

		.title {
			padding: 30rpx 0;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}

		.xyInfo-box {
			.item {
				display: flex;
				padding-bottom: 16rpx;

				.label {
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}

	.orderInfo {
		height: 284rpx;
		background: #FEF1DC;
		border-radius: 20rpx;
		padding: 0 30rpx;

		.title {
			padding: 30rpx 0;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}

		.xyInfo-box {
			.item {
				display: flex;
				padding-bottom: 16rpx;

				.label {
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}

	.button-box {
		box-sizing: border-box;
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 124rpx;
		background: #FEF1DC;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.left {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #6A2D0A;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
		}

		.right {
			display: flex;

			.left-btn,
			.right-btn {
				width: 220rpx;
				height: 84rpx;
				border-radius: 42rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				line-height: 84rpx;
				text-align: center;
				font-style: normal;
			}

			.left-btn {
				color: #D06122;
				border: 2rpx solid #D06122;
			}

			.right-btn {
				color: #FFFFFF;
				margin-left: 20rpx;
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
			}
		}
	}

	.pay-popup {
		width: 570rpx;
		height: 636rpx;
		background: linear-gradient(270deg, #FFFFFF 0%, #F2D8AE 100%);
		border-radius: 40rpx;
		box-sizing: border-box;

		.close {
			width: 90rpx;
			height: 90rpx;
			position: absolute;
			bottom: -150rpx;
			left: 50%;
			transform: translateX(-50%);
			border: 8rpx solid white;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.successful-img {
			height: 120rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.popup-box {
			width: 570rpx;
			height: 516rpx;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.ok-img {
				padding-top: 56rpx;
			}

			.text {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
				padding-top: 44rpx;
			}

			.btns {
				padding-top: 80rpx;
				display: flex;
				justify-content: space-between;
				width: 450rpx;

				.left-btn {
					width: 200rpx;
					height: 84rpx;
					background: #A3A3A3;
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}

				.right-btn {
					width: 200rpx;
					height: 84rpx;
					background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}
			}
		}
	}
</style>